/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * \file
 * \brief Question dialog implementation.
 * \author Antti Maula <antti.maula@tkk.fi>
 * \author wxFormBuilder (Autogenerated base code)
 *
 * $Id: MaCI_AlarmQuestionDialog.cpp,v 1.3 2009-04-27 13:00:54 amaula Exp $
 *
 */
#include "MaCI_AlarmQuestionDialog.h"
#include "MaCI_AlarmMainFrame.h"  // For the QUESTIONDIALOGEVENT

//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************

MaCI_AlarmQuestionDialog::MaCI_AlarmQuestionDialog( wxWindow* parent )
  : QuestionDialog( parent ),
    iTimeout_ms(0),
    iTimeout_begin(0)
{
  
}
//*****************************************************************************

void MaCI_AlarmQuestionDialog::OnCloseButtonClick( wxCloseEvent& event )
{
  dPrint(ODTEST,"Called");
  wxCommandEvent e( MY_EVENT_QUESTIONDIALOGEVENT, wxWindowBase::GetId());
  iAlarmInfoPtr->SetAnswer(KAnswerIgnore);
  e.SetClientData(iAlarmInfoPtr);
  GetParent()->AddPendingEvent(e);
  
  Destroy();
}
//*****************************************************************************

void MaCI_AlarmQuestionDialog::OnYesButtonClick( wxCommandEvent& event )
{
  dPrint(ODTEST,"Called");
  wxCommandEvent e( MY_EVENT_QUESTIONDIALOGEVENT, wxWindowBase::GetId());
  iAlarmInfoPtr->SetAnswer(KAnswerYes);
  e.SetClientData(iAlarmInfoPtr);
  GetParent()->AddPendingEvent(e);

  Destroy();
}
//*****************************************************************************

void MaCI_AlarmQuestionDialog::OnNoButtonClick( wxCommandEvent& event )
{
  dPrint(ODTEST,"Called");
  wxCommandEvent e( MY_EVENT_QUESTIONDIALOGEVENT, wxWindowBase::GetId());
 
  iAlarmInfoPtr->SetAnswer(KAnswerNo);
  e.SetClientData(iAlarmInfoPtr);
  GetParent()->AddPendingEvent(e);

  Destroy();
}
//*****************************************************************************

void MaCI_AlarmQuestionDialog::SetQuestion(const std::string &aSource, 
                                           const std::string &aMessage,
                                           const unsigned int aTimeout)
{
  this->SetTitle(std::string("Q - ") + aSource);
  questionSourceStaticText->SetLabel(aSource);
  questionBodyTextCtrl->SetValue(aMessage);

  if (aTimeout > 0) {
    iTimeout_begin = ownTime_get_ms();
    iTimeout_ms = aTimeout;
    timeoutStaticText->SetLabel(wxString::Format("%d s", aTimeout/1000));
    
    // Execute timer :)
    Start(200);

  } else {
    timeoutLeftPanel->Hide();

  }
}
//*****************************************************************************

void MaCI_AlarmQuestionDialog::SetAlarmInfoPtr(SAlarmInfo *aData)
{
  iAlarmInfoPtr = aData;
}
//*****************************************************************************

void MaCI_AlarmQuestionDialog::Notify()
{
  ownTime_ms_delta_t tleft = ownTime_get_ms_left(iTimeout_begin, iTimeout_ms);
  
  if (tleft > 0) {
    timeoutStaticText->SetLabel(wxString::Format("%d s", tleft/1000));
    
  } else {
    wxCloseEvent ce;
    OnCloseButtonClick(ce);
  }
}
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
